// components/swiper-img/swiper-img.js
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的属性列表
   */
  properties: {},

  /**
   * 组件的初始数据
   */
  data: {
    cardCur: 0,
    swiperList: [
      {
        id: 0,
        type: 'image',
        name: '熊猫',
        classify: '哺乳类',
        url: 'cloud://cloud1-7g0jzi1h34a3b0ce.636c-cloud1-7g0jzi1h34a3b0ce-1318866511/classify/panda.webp'
      },
      {
        id: 1,
        type: 'image',
        name: '丹顶鹤',
        classify: '鸟类',
        url: 'cloud://cloud1-7g0jzi1h34a3b0ce.636c-cloud1-7g0jzi1h34a3b0ce-1318866511/classify/丹顶鹤.jpg'
      },
      {
        id: 2,
        type: 'image',
        name: '大白鲨',
        classify: '鱼类',
        url: 'cloud://cloud1-7g0jzi1h34a3b0ce.636c-cloud1-7g0jzi1h34a3b0ce-1318866511/classify/大白鲨.jpg'
      },
      {
        id: 3,
        type: 'image',
        name: '棱皮龟',
        classify: '爬行类',
        url: 'cloud://cloud1-7g0jzi1h34a3b0ce.636c-cloud1-7g0jzi1h34a3b0ce-1318866511/classify/龟.jpg'
      },
      {
        id: 4,
        type: 'image',
        name: '青蛙',
        classify: '两栖类',
        url: 'cloud://cloud1-7g0jzi1h34a3b0ce.636c-cloud1-7g0jzi1h34a3b0ce-1318866511/classify/青蛙.jpg'
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 去分类页面
    toCollectionClassify() {
      wx.navigateTo({
        url: '/pageCollectionClassify/pages/collection-classify/collection-classify'
      })
    },
    // 初始化towerSwiper
    towerSwiper(name) {
      let list = this.data[name]
      for (let i = 0; i < list.length; i++) {
        list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
        list[i].mLeft = i - parseInt(list.length / 2)
      }
      this.setData({
        swiperList: list
      })
    },
    // cardSwiper
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    }
  },

  lifetimes: {
    attached() {
      // 初始化towerSwiper 传已有的数组名即可
      this.towerSwiper('swiperList')
      // wx.showLoading({
      //   title: "插入中",
      //   mask: true
      // });
      // wx.showToast({
      //   title: "插入成功",
      //   icon: "error"
      // })
    }
  }
})
